package com.example.homecunter.news.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.example.homecunter.R;
import com.example.homecunter.news.newsentity.NewsEntity;
import com.example.homecunter.video.adapter.VideoAdapter;
import com.example.homecunter.video.entity.VideoEntity;
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer;

import java.util.List;

public class NewsAdapter extends RecyclerView.Adapter<NewsAdapter.NewsViewHodel> {
        Context context;
        List<NewsEntity> data;

        LayoutInflater inflater;

    public NewsAdapter(Context context, List<NewsEntity> data) {
            this.context = context;
            this.data = data;

            inflater = LayoutInflater.from(context);
        }

        @NonNull
        @Override
        public NewsViewHodel onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
            return new NewsViewHodel(inflater.inflate(R.layout.item_news,parent,false));
        }


        @Override
        public void onBindViewHolder(@NonNull NewsAdapter.NewsViewHodel holder, int position) {
            Glide.with(context).load(data.get(position).getMainimgurl()).into(holder.img);


            holder.item_tv.setText(data.get(position).getTitle());
        }

        @Override
        public int getItemCount() {
            return data.size();
        }

        public class NewsViewHodel extends RecyclerView.ViewHolder {
            ImageView img;
            TextView item_tv;
            public NewsViewHodel(@NonNull View itemView) {
                super(itemView);
                img = itemView.findViewById(R.id.item_news_iv);
                item_tv = itemView.findViewById(R.id.item_news_tv);
            }
        }
}
